package com.hst.capacity.infra.persistence.jpa.setting.price;

import com.hst.capacity.domain.model.entity.setting.price.AirportPriceEntity;
import com.hst.capacity.domain.model.response.setting.price.AirportSearchVO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface AirportPriceEntityRepository extends JpaRepository<AirportPriceEntity, String> {

    @Query("select new com.hst.capacity.domain.model.response.setting.price.AirportSearchVO(p,a) from AirportPriceEntity p left join AirportEntity a on p.idAirport=a.idAirport where p.idFranchisee=:idFranchisee")
    Page<AirportSearchVO> findByIdFranchisee(String idFranchisee, PageRequest pageRequest);

    /**
     * 通过地区查找站点价格
     * @param regionCode
     * @return
     */
    @Query("select o " +
            "from AirportPriceEntity o " +
            "inner join FranchiseeEntity a on a.idFranchisee = o.idFranchisee " +
            "where a.regionCode =:regionCode ")
    List<AirportPriceEntity> findByRegionCode(@Param("regionCode")String regionCode);

    /**
     * 通过地区查找站点价格
     * @param idAirport
     * @return
     */
    @Query("select o " +
            "from AirportPriceEntity o " +
            "where o.idFranchisee =:idFranchisee " +
            "and o.idAirport =:idAirport " +
            "and o.idServiceType =:idServiceType " +
            "and o.idVehicleType =:idVehicleType " )
    AirportPriceEntity findByIdAirport(@Param("idFranchisee")String idFranchisee, @Param("idAirport")String idAirport, @Param("idServiceType")int idServiceType, @Param("idVehicleType")int idVehicleType);

}